package com.yanqu.road.server.channelserver.cmd.chat;

import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.pb.cross.activity.CrossActivityProto;
import com.yanqu.road.server.protocol.Cross3Protocol;
import com.yanqu.road.server.channelserver.cmd.ChannelCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.channelserver.logic.ChannelMessageHelper;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ChannelProtocol;

@Cmd(code = ChannelProtocol.N_CHANNEL_ACTIVITY_MESSAGE_TRANSFER, desc = "活动聊天消息转发")
public class ChannelMessageTransferCmd extends ChannelCommand {

    private CrossActivityProto.CrossActivityChatReqMsg reqMsg;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        reqMsg = CrossActivityProto.CrossActivityChatReqMsg.parseFrom(packet.getBytes());
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        int channelId = reqMsg.getChannelId();

        CrossActivityProto.CrossActivityChatReqMsg.Builder builder = reqMsg.toBuilder();
        builder.setSyncChannel(false);
        builder.clearChannelId();

        // 同步到别的地区
        YanQuMessage message = YanQuMessageUtils.buildMessage(Cross3Protocol.C3_CROSS_ACTIVITY_CHAT, builder);
        ChannelMessageHelper.sendOtherChannel(message, channelId);
    }

    @Override
    public void sendData() {

    }
}
